package core;


public class Clock implements Runnable {
	
	private static int numIdClock;
	private String id = "CLOCK_";
	private int time;
	private boolean stop = false;
	
	private Controler controler;
	
	public Clock() {
		numIdClock++;
		id += numIdClock;
	}
	
	public Clock(Controler controler) {
		this.controler = controler;
	}
	
	public void setControler(Controler controler) {
		this.controler = controler;
	}
	
	public void setStop(boolean value) {
		stop = value;
	}

	@Override
	public void run() {
		while (!stop) {
			time++;
			System.out.println(id + " : " + time);
			if (controler != null) controler.updateWindow("" + time);
		}
	}
	
	@Override
	public String toString() {
		return id;
	}
	
	public static void main(String[] args) {
		Clock clock = new Clock();
		Thread worker = new Thread(clock);
		worker.start();
		
		try {
			Thread.sleep(5000);
			clock.setStop(true);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
